<?php 
	ob_start(); session_start(); 
	require_once('adminpanel/config/setting.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Menu</title>
</head>
<style>
	.topmenu{
		font-family:arial;
		font-size:14px;
		color:#FFFFFF;
		text-decoration:none;
	}
	.topmenu:hover{
		font-family:arial;
		font-size:14px;
		color:#FFFFFF;
		text-decoration:underline;
	}
</style>

<body style="margin:0px; background-color:#f1f1f1">
	<div id="header" style="background:url(images/top-bg.png) repeat-x; " align="center">
    	<div style="width:982px;" >
        	<div style="padding-top:30px; padding-right:20px; color:#FFFFFF" align="right">
            	<img src="images/the-century-logo.png" style="top:20px; margin-left:50px;" align="left" />
            	<a href="index.php" class="topmenu">Home</a> &nbsp; | &nbsp; 
                <a href="about-us.php" class="topmenu">About Us</a> &nbsp; | &nbsp; 
                <a href="questions.php" class="topmenu">Questions</a> &nbsp; | &nbsp; 
                <a href="reservation.php" class="topmenu">Reservation</a> &nbsp; | &nbsp; 
				<a href="menu.php" class="topmenu"><font size="5px">Menu</font></a> &nbsp; | &nbsp; <?php if(!($_SESSION['username'])){?>
                <a href="signup.php" class="topmenu">Signup</a><?php } else {?>
                <a href="logout.php" class="topmenu">Logout</a><?php }?>
                <br /><br />
                <?php 
                include('login.php');
				?>            
            </div>
        	<img src="images/top-gradient.png" />
            <div style="position:absolute; top:200px; margin-left:50px; font-size:24px; color:#F00 ">Menu</div>
        </div>
    </div>
	<div id="body" align="center">
    	<div style="width:982px" align="center">
            <div style="width:900px;margin-left:0px; line-height:18px; font-family:verdana; font-size:12px; color:#666" align="left" >
            <input type="button" value="Menu" style="height:50px; width:200px"  onClick="location.href='menu.php'"/> 
            <input type="button" value="Group Menu" style="height:50px;  width:200px" onClick="location.href='menu.php?type=groupmenu'" /> 
            <table cellpadding="2" style="color:#74463e">
            	<tr>
                	<td valign="top" width="600px" bgcolor="#FFFFFF">
                    	<div style="width:600px; height:600px; overflow:auto">
						<? 
						
						function getcat($tmpid){
							$result = mysql_query("select * from tbl_category where id='$tmpid' limit 1" ) or die (mysql_error());
							if ($row = mysql_fetch_array($result)){							
								$catname = $row['category'];
							}
							return $catname;
						}

						if($_GET['type']=='groupmenu'){
							echo '<h1>List of Group Menus</h1><hr>';
							$result = mysql_query("select * from tbl_groupmenu where active='1'") or die (mysql_error());
							while ($row = mysql_fetch_array($result)){
								$id = $row['id'];
								$name = $row['name'];
								$price = $row['price'];
								$smeals = $row['nmeals'];
								$arr_meal = explode(',', $smeals);
								$mealno = count($arr_meal);
								$nmeals= '';
								for($i=0;$i<$mealno;$i++){
									$mealid = $arr_meal[$i];
									$mresult = mysql_query("select * from tbl_menu where id='$mealid' limit 1") or die (mysql_error());
									if ($mrow = mysql_fetch_array($mresult)){
										$nmeals .= '<li>'.$mrow['name'].'</li>';
									}
								}
								
								echo '
									<div style="margin:10px; height:auto; border-bottom:solid 1px #fea5a5; padding-bottom:15px ">
										<b>'.$name.'</b><br />
										<ol>'.$nmeals.'</ol>
										<b>Php '.$price.'</b>
									</div>
								';
							}		
							if(mysql_num_rows($result)==0){
								echo ' <br><br>&nbsp; &nbsp; <b>No Group Meal Found!</b>';
							}
						}else{
							
							if($_GET['cat']){
								$cat = $_GET['cat'];
								$result = mysql_query("select * from tbl_menu where active='1' and category='$cat' ") or die (mysql_error());
								echo '<h1>List of '.getcat($cat).' Menus</h1><hr>';
							}else{
								$result = mysql_query("select * from tbl_menu where active='1'") or die (mysql_error());
								echo '<h1>List of Available Menus</h1><hr>';
							}
							while ($row = mysql_fetch_array($result)){
								$id = $row['id'];
								$name = $row['name'];
								$price = $row['price'];
								$picture = $row['picture'];
								$catid = $row['category'];
								$description = $row['description'];
								if($picture){
								    $npict = 'uploads/'.$picture;	
								}else{
									$npict = 'images/no-photo.png';
								}
								echo '
										<div style="margin:10px; height:165px; border-bottom:solid 1px #fea5a5; padding-bottom:15px ">
											<img src="'.$npict.'" width="275px" height="170px" align="right" style="padding-left:15px" />
											<b>'.$name.'</b><br />
											'.$description.'<br />
											<b>Php '.$price.'</b>
										</div>
								';
							}		
							if(mysql_num_rows($result)==0){
								echo ' <br><br>&nbsp; &nbsp; <b>No Meal Found!</b>';
							}
						}
						?>	
                     </div>
                    </td>    
                    <td valign="top" width="300px">
						<?php 
							$result = mysql_query("select * from tbl_category") or die (mysql_error());
							while ($row = mysql_fetch_array($result)){
								$id = $row['id'];
								$category = $row['category'];
								echo '<input type="button" value="'.$category.'" onClick="location.href=\'menu.php?cat='.$id.'\'" style="height:50px; font-size:11px; width:140px" /> ';
							}
						?>	
					
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="footer" style="background:url(images/btm-bg.png) repeat-x; height:166px" align="center">
    	<div style="width:982px">
        	<div style="height:40px"></div>
        	<img src="images/btm-gradient.png" />
        </div>
    		
    </div>
</body>
</html>